package com.qin.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.qin.service.OrderService;
import com.qin.service.impl.OrderServiceImpl;

/**
 * 用户删除订单
 */
@WebServlet("/deleteOrder")
public class DeleteOrderServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	private OrderService orderService = new OrderServiceImpl();
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// 拿到要删除的orderId
		String parameter = request.getParameter("orderId");
		
		// 删除
		int logicDeleteOrder = orderService.logicDeleteOrder(Long.parseLong(parameter));
		
		if(logicDeleteOrder!=0) {
			
			// 成功后重定向到订单页面
			response.sendRedirect(request.getContextPath()+"/orders");
		}else {
			// 回首页
			response.sendRedirect(request.getContextPath());
		}
	
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
